package NET.webserviceX.www;

import java.io.File;
import java.io.StringReader;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
    "location",
	"time",
	"wind",
	"skyConditions",
	"temperature",
	"dewPoint",
	"relativeHumidity",
	"pressure",
	"status"
})
@XmlRootElement(name = "CurrentWeather")
public class Meteo2 {
	@XmlElement(name="Location")
	private String location;
	@XmlElement(name="Time")
	private String time;
	@XmlElement(name="Wind")
	private String wind;
	@XmlElement(name="SkyConditions")
	private String skyConditions;
	@XmlElement(name="Temperature")
	private String temperature;
	@XmlElement(name="DewPoint")
	private String dewPoint;
	@XmlElement(name="RelativeHumidity")
	private String relativeHumidity;
	@XmlElement(name="Pressure")
	private String pressure;
	@XmlElement(name="Status")
	private String status;
	
	public static void main(String[] args) {
		
		GlobalWeather gw = new GlobalWeatherLocator(); // get a service instance
		try {
			GlobalWeatherSoap gwss = gw.getGlobalWeatherSoap();

			/* METHODE 2 : ON INSTANCIE DIRECTEMENT L'OBJET METEO2 GRACE AUX ANNOTATIONS */
			JAXBContext context = JAXBContext.newInstance(NET.webserviceX.www.Meteo2.class);
			
			Unmarshaller u = context.createUnmarshaller();
			
			// La ligne commentee qui suit permet de tester meme si le web service ne fonctionne pas
			//Meteo2 meteo = (Meteo2) u.unmarshal(new File("prévisions.xml"));
			
			Meteo2 meteo = (Meteo2) u.unmarshal(new StringReader(gwss.getWeather("Paris / Le Bourget", "France")));
			
			System.out.println("\n\nJ'interroge maintenant mon objet Java pour connaître la météo :");
			
			System.out.println("Voici la météo de "+meteo.getLocation());
			
			System.out.println("Ce bulletin date de "+meteo.getTime());
			
			System.out.println("Le vent vient "+meteo.getWind());
			
			System.out.println("La temperature est de "+meteo.getTemperature());
			
			System.out.println("Le ciel est "+meteo.getSkyConditions());
			
			System.out.println("Votre baromètre doit afficher : "+meteo.getPressure());
			
			System.out.println("L'hygrométrie est de : "+meteo.getRelativeHumidity());
			
			System.out.println("Le point de rosée est à : "+meteo.getDewPoint());		

		} catch(Exception e) {
			e.printStackTrace();
		}

	}

	public String getLocation() {
		return location;
	}

	public void setLocation(String location) {
		this.location = location;
	}

	public String getTime() {
		return time;
	}

	public void setTime(String time) {
		this.time = time;
	}

	public String getWind() {
		return wind;
	}

	public void setWind(String wind) {
		this.wind = wind;
	}

	public String getSkyConditions() {
		return skyConditions;
	}

	public void setSkyConditions(String skyConditions) {
		this.skyConditions = skyConditions;
	}

	public String getTemperature() {
		return temperature;
	}

	public void setTemperature(String temperature) {
		this.temperature = temperature;
	}

	public String getDewPoint() {
		return dewPoint;
	}

	public void setDewPoint(String dewPoint) {
		this.dewPoint = dewPoint;
	}

	public String getRelativeHumidity() {
		return relativeHumidity;
	}

	public void setRelativeHumidity(String relativeHumidity) {
		this.relativeHumidity = relativeHumidity;
	}

	public String getPressure() {
		return pressure;
	}

	public void setPressure(String pressure) {
		this.pressure = pressure;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

}